//
//  HomeBoard.m
//  Pizza
//
//  Created by sendInfo on 2015-03-16.
//  Copyright (c) 2015年 sendInfo. All rights reserved.
//

#import "HomeBoard.h"
#import "TopView.h"
#import "Masonry.h"
#import "ShopBoard.h"
#import "SortBoard.h"
#import "FriendCell.h"
#import "DecorateBoard.h"
#import "SafeBoxContentCell.h"
#import "RevealController.h"
#import "RevealViewController.h"
#import "AppDelegate.h"
#import "bee.services.share.weixin.h"
#import "ShareWeiBo.h"
#import "CartBoard.h"
#import "FanLiItemCell.h"
#import "MyLinksCell.h"
#import "ShopBoard.h"
#import "FootLoader.h"
#import <AlipaySDK/AlipaySDK.h>

@implementation FeeItemCell


- (void)load
{

   _bg = [[UIView alloc] init];
   [self addSubview:_bg];
    
    _feelab = [[UILabel alloc] init];
    [self addSubview:_feelab];
    
}
- (void)dataDidChanged
{

    _feelab.text = self.data;

}
- (void)layoutDidFinish
{

    _bg.frame = CGRectMake(0, 10, self.size.width, 44-10);
    _bg.backgroundColor = [UIColor whiteColor];
    
    _feelab.frame = CGRectMake(10, 18, self.size.width-20, 16);
    _feelab.font = [UIFont systemFontOfSize:16];
    _feelab.textColor = [UIColor blackColor];

}
@end

@implementation PayTypeCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
   
    NSDictionary *dic = self.data;
    $(@"icon").DATA(dic[@"icon"]);
    $(@"title").DATA(dic[@"title"]);
    
}

@end


@implementation PayAddressCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    
    Address *add = self.data;
    $(@"name").DATA(add.name);
    $(@"phone").DATA(add.mobile);
    $(@"addr").DATA(add.address);
}

@end

@implementation PayAllNumCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    NSDictionary *dic = self.data;
    $(@"number").DATA(dic[@"nums"]);
    $(@"price").DATA([NSString stringWithFormat:@"￥ %@",dic[@"price"]]);
  
}

@end

@implementation PayGoodsCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    CartM *cm = self.data;
    $(@"name").DATA(cm.goods.title);
    $(@"number").DATA(cm.goodsNum);
    $(@"price").DATA(cm.goods.price);
    NSString *url = [NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].imageUrl,cm.goods.pic];
    $(@"photo").DATA(url);
    
}

@end


@implementation SafeBoxLoginCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    
    NSString *type = self.data;
    if ([type isEqualToString:@"pass"]) {
        
        $(@"questionTf").HIDE();
        $(@"passTf").HIDE();
        BeeUITextField *tf = (BeeUITextField*)$(@"answerTf").view;
        tf.placeholder = @"输入密码";
        tf.secureTextEntry = YES;
        $(@"title").TEXT(@"输入保险柜密码");
        $(@"sureopen").TEXT(@"确认密码");
        
    }else if ([type isEqualToString:@"forget"])
    {
    
        $(@"questionTf").SHOW();
        $(@"passTf").SHOW();
        BeeUITextField *tf = (BeeUITextField*)$(@"questionTf").view;
        tf.text = @"你的母亲叫什么名字?";
        $(@"title").TEXT(@"找回保险柜密码");
        $(@"sureopen").TEXT(@"确认");
    
    
    }
    else{
    
        $(@"questionTf").SHOW();
        $(@"passTf").SHOW();
        BeeUITextField *tf = (BeeUITextField*)$(@"answerTf").view;
        tf.placeholder = @"回答密保问题";
        $(@"title").TEXT(@"保险柜");
        $(@"sureopen").TEXT(@"确认打开");
    
    }
    
}
- (void)layoutSubviews
{

    
}
@end


@implementation EditInfoAddressCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    Address *adr = self.data;
    $(@"nametf").DATA(adr.name);
    $(@"phonetf").DATA(adr.mobile);
    $(@"addrtf").DATA(adr.address);
}

@end


@implementation EditInfoCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    //发请求
    
    self.MSG(HttpAPI.member_info).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken});
    self.MSG(HttpAPI.aboutus).INPUT(@"body",@{});
    
}
ON_MESSAGE3(HttpAPI, aboutus, msg)
{


    if (msg.sending) {
        
        
    }else{
        
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            NSDictionary *infoD = msg.GET_OUTPUT(@"info");
            
            BeeUIImageView *img = (BeeUIImageView *)$(@"qrimg").view;
            [img GET:[NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].url,infoD[@"pic"]] useCache:YES placeHolder:[UIImage imageNamed:@"qercode"]];
            
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
    

}
- (void)dataDidChanged
{
    
     Member *mem = self.data;
     $(@"shopnametf").DATA(mem.shopName);
     $(@"ownernametf").DATA(mem.memberName);
     $(@"phonetf").DATA(mem.mobile);
     $(@"adtf").DATA(mem.slogan);
    
    
    //只显示一个地址
    NSArray *addr = mem.address;
    Address *adr = [addr firstObject];
    $(@"addressone").DATA(adr.address);
    
//    $(@"addresstwo").HIDE();
//    $(@"pei2").HIDE();
//    $(@"xiu2").HIDE();
    
//    else if (addr.count<=2){
//    
//        Address *adr = addr[0];
//        Address *adr1 = addr[1];
//        $(@"addressone").DATA(adr.address);
//        $(@"addresstwo").DATA(adr1.address);
//    }
}

ON_MESSAGE3(HttpAPI, member_info, msg)
{


    if (msg.sending) {
        
        [self presentLoadingTips:@"获取信息"];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {

            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            Member *mem = msg.GET_OUTPUT(@"memberinfo");
            [[NSUserDefaults standardUserDefaults] setObject:mem.pic forKey:@"userphoto"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            self.data = mem;
            
            $(@"userIcon").DATA([NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].imageUrl,mem.pic]);
            
            
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }




}

@end

@implementation NewsDetailCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    $(@"detail").DATA(self.data);
}

@end

@implementation NewsItemCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    News *nw = self.data;
    $(@"title").DATA(nw.title);
    $(@"content").DATA(nw.content);
    BeeUIImageView *icon = (BeeUIImageView*)$(@"icon").view;
    [icon GET:[NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].imageUrl,nw.pic] useCache:YES placeHolder:[UIImage imageFromString:@"newsicon"]];
    $(@"time").DATA(nw.create_time);
   
    
}

@end

@interface NewsCell(){
    
    NewsItemCell *_currentCell;
    
}
@property (nonatomic,strong)NSArray *datas;
@end

@implementation NewsCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
 
   self.MSG(HttpAPI.notice).INPUT(@"body",@{@"source":@"IOS",@"productPageSize":@"1000",@"pageNumber":@"1"});
    
    self.list.lineCount = 1;
    self.list.animationDuration = 0.25f;
    self.list.whenReloading = ^{
    
        if (_currentCell) {
             self.list.total = 1;
        }else{
             self.list.total = self.datas.count;
        }
        
       
        
        for (BeeUIScrollItem *item in self.list.items) {
            
            
            if (_currentCell) {
             
                item.size = CGSizeAuto;
                item.clazz = [NewsDetailCell class];
                item.data = self.data;
            }else{
            
               
                item.size = CGSizeMake(self.list.size.width, 80);
                item.clazz = [NewsItemCell class];
                item.data = [self.datas safeObjectAtIndex:item.index];
            }
            
            
        }
    
    };
    
    
    
}
- (void)dataDidChanged
{
    
    
}
ON_SIGNAL3(NewsItemCell, mask, signal)
{


    _currentCell = (NewsItemCell *)signal.sourceCell;
    News *nw = _currentCell.data;
    
    self.MSG(HttpAPI.notice_detail).INPUT(@"body",@{@"id":nw.id});
    
   

}
ON_MESSAGE3(HttpAPI, notice_detail, msg)
{

    if (msg.sending)
    {
        [self presentLoadingTips:@""];
        
    }else
    {
        [self dismissTips];
        
        if (msg.succeed)
        {
             self.data = msg.GET_OUTPUT(@"content");
             [self.list reloadData];
            
        }else if (msg.failed)
        {
            
            [self presentFailureTips:msg.GET_OUTPUT(@"message")];
            
        }
        
    }


}
ON_MESSAGE3(HttpAPI, notice, msg)
{

    if (msg.sending)
    {
        [self presentLoadingTips:@""];
        
    }else
    {
        [self dismissTips];
        
        if (msg.succeed)
        {
            self.datas = msg.GET_OUTPUT(@"news");
            [self.list reloadData];
            
            
        }else if (msg.failed)
        {
            [self presentFailureTips:@"网络故障"];
            
        }
        
    }


}
@end

@implementation FindPassCell


- (void)load
{
    
}
- (void)dataDidChanged
{
   
    
}

@end

@implementation FanLiCell
SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    NSArray *titles = @[@"食客",@"地摊",@"档口",@"小店",@"大店",@"一星店",@"二星店",@"三星店",@"四星店",@"五星店",@"说明"];
    
    NSArray *values = @[@"用户下载app后完成注册即成为食客 无店铺（是唯一无店铺的级别）",
                        @"食客级首次在其他用户店铺完成购买披萨后即刻升级为地摊（该级别用户可在自己店铺购买披萨，其他用户也可在此店进行购买",
                        @"用户店铺累计有1次食客级用户在本店完成一次购买后即刻升级为档口（升级后用户就可永久享受所辖一级连锁店每销售一单5元的利润分红） ",
                        @"用户店铺累计有2次食客级用户在本店完成一次购买后即刻升级为小店（升级后用户可永久享受所辖二级连锁店每销售一单2元的利润分红）",
                        @"用户店铺累计有4次食客级用户在本店完成一次购买后即刻升级为大店（升级后用户可永久享受所辖三级连锁店每销售一单2元的利润分红）",
                        @"店铺累计有6次食客级用户在本店完成一次购买后即刻升级为一星店（升级后用户可永久享受所辖四级连锁店每销售一单2元的利润分红）",
                        @"店铺累计有8次食客级用户在本店完成一次购买后即刻升级为二星店（升级后用户可永久享受所辖五级连锁店每销售一单2元的利润分红）",
                        @"店铺累计有18次食客级用户在本店完成一次购买后即刻升级为三星店（所辖连锁店总数达到2000个时，每月将额外获得利润分红1000元）",
                        @"店铺累计有38次食客级用户在本店完成一次购买后即刻升级为四星店（所辖连锁店总数达到4000个时，每月将额外获得利润分红3000元）",
                        @"店铺累计有68次食客级用户在本店完成一次购买后即刻升级为五星店（所辖连锁店总数达到6000个时，每月将额外获得利润分红6000元）",
                        @"所有档口级以上店铺（含档口级），每月至少销售一单，到期未完成的用户店铺，系统将自动封锁该店铺保险柜，当该店铺补齐销售后，保险柜自动解封。"
                           ];
    
    self.list.lineCount = 1;
    self.list.animationDuration = 0.5f;
    self.list.whenReloading = ^{
    
        self.list.total = titles.count;
        
        for (BeeUIScrollItem *item in self.list.items) {
            
            item.size = CGSizeMake(self.list.width, 85);
            item.clazz = [FanLiItemCell class];
            item.data = @[titles[item.index],values[item.index]];
        }

    
    };
    
}
- (void)dataDidChanged
{
    
}

@end




@implementation LoginCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{
    
    
}
- (void)dataDidChanged
{
    
}

@end

@implementation RegisterCell

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

- (void)load
{


}
- (void)dataDidChanged
{

}

@end

@interface HomeBoard ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>{

    NSMutableArray *shopDatas;
    int _row;
    int _col;
    
    
    UIView *addv;
    FriendCell *fcell;
    NSArray *shareicons;
    
    BeeUIScrollView *scr;
    UIImageView *bgimg;
    
    NSString *_mphone;
    NSString *_apivercode;
    
    UIView *payBottomV;
    
    PayTypeCell *_lastPayTypeCell;
    

    EditInfoCell *editCell;
    

}


@property (nonatomic,strong)BeeUIScrollView *payList;
@property (nonatomic,strong)NSString  *imagePath;
@end

@implementation HomeBoard

SUPPORT_AUTOMATIC_LAYOUT(YES)
SUPPORT_RESOURCE_LOADING(YES)

ON_WILL_APPEAR(signal)
{
    

     if (self.homeType) {
        
        return;
    }

    if ([SendIFAPPDefault shareAppDefault].userToken.length==0) {
        
        [self presentLoginView];
        return;
    }
   
    //获取首页数据
    NSString *tok = [SendIFAPPDefault shareAppDefault].userToken.length==0?@"":[SendIFAPPDefault shareAppDefault].userToken;
    NSDictionary *dic = @{@"source":@"",@"token":tok,@"pageNumber":@"1",@"pageSize":@"1000"};
    self.MSG(HttpAPI.GETHOME).INPUT(@"body",dic);


    
}
ON_WILL_DISAPPEAR(signal)
{

    if ([self.homeType isEqual:@"fanli"]) {
        
        [self dismissModalViewAnimated:NO];
    }
    
}
ON_MESSAGE3(HttpAPI, member_info, msg)
{
    

    if (msg.sending) {
        
        //[self presentLoadingTips:@"正在登录"];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            //Member *meb = msg.GET_OUTPUT(@"memberinfo");
            //[self addBottomView:meb];
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
    


}

#pragma mark - 更新token
ON_MESSAGE3(HttpAPI, UPDATETOKEN, msg)
{
 


    if (msg.sending) {
        
        [self presentLoadingTips:@"更新token"];
    }else{
        
        [self dismissTips];
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                
                [self presentLoginView];
                return;
            }
            //
            [[SendIFAPPDefault shareAppDefault] setUserToken:msg.GET_OUTPUT(@"token")];
            //self.MSG(HttpAPI.member_info).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken?:@" "});
            [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:[NSDate timeStamp]] forKey:@"login_time"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            NSString *tok = [SendIFAPPDefault shareAppDefault].userToken.length==0?@"":[SendIFAPPDefault shareAppDefault].userToken;
            NSDictionary *dic = @{@"source":@"",@"token":tok,@"pageNumber":@"1",@"pageSize":@"1000"};
            self.MSG(HttpAPI.GETHOME).INPUT(@"body",dic);
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
        }
        
    }
    
}
ON_DID_DISAPPEAR(signal)
{

    self.homeType = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationBarShown = NO;

    //首页店铺
    shopDatas = [[NSMutableArray alloc] initWithCapacity:0];
    [shopDatas addUniqueObjectsFromArray:[Shop readObjectForKey:@"home.shops"]
                                  compare:^NSComparisonResult(id left, id right) {
                                      return [((Shop *)left).id compare:((Shop *)right).id];
                                  }];
    
    shareicons = @[[UIImage imageFromString:@"qq"],[UIImage imageFromString:@"weixin"],[UIImage imageFromString:@"tencent"],[UIImage imageFromString:@"sina"]];
    
    _row = (int)(shopDatas.count/2);
   
    if (shopDatas.count%2) {
        
        _row++;

    }
    if (shopDatas.count==1) {
        
        _row=1;
    }
    
    [self addUI];
    
    
    //个人中心
    if ([self.homeType isEqualToString:@"editinfo"]) {
        
        if ([[SendIFAPPDefault shareAppDefault].loginState intValue] == 0) {
            
            
            [self performSelector:@selector(presentLoginView) withObject:nil afterDelay:0.3];
            
        }else{
            
           
            [self performSelector:@selector(presentEditInfoView) withObject:nil afterDelay:0.3];
        }
        
        return;
    }
    
    //保险箱
    if ([self.homeType isEqualToString:@"safebox"]) {
        
        if ([[SendIFAPPDefault shareAppDefault].loginState intValue] == 0) {
            
            
            [self performSelector:@selector(presentLoginView) withObject:nil afterDelay:0.3];
            
        }else{
            
            
            [self performSelector:@selector(presentLoginSafeBox) withObject:nil afterDelay:0.3];
        }
        
        return;
    }
    
    //支付样式
    if ([self.homeType isEqualToString:@"pay"]) {
        return;
    }
    if ([self.homeType isEqualToString:@"fanli"]) {
        
        return;
    }
    
    //获取首页数据
    NSString *tok = [SendIFAPPDefault shareAppDefault].userToken.length==0?@"":[SendIFAPPDefault shareAppDefault].userToken;
    NSDictionary *dic = @{@"source":@"",@"token":tok,@"pageNumber":@"1",@"pageSize":@"1000"};
    self.MSG(HttpAPI.GETHOME).INPUT(@"body",dic);
    

    NSString *uid = [SendIFAPPDefault shareAppDefault].currentUserID;
    
    if(uid.length>0){
        
        
        long long lastLogin = [[[NSUserDefaults standardUserDefaults] objectForKey:@"login_time"] longLongValue];
        if (([NSDate timeStamp]- lastLogin)/60 > 3) {
            
            //更新token
            
            self.MSG(HttpAPI.UPDATETOKEN).INPUT(@"body",@{@"token":tok,@"userId":uid,@"channelId":@""});
            
            
        }
    }
}

#pragma mark - 添加店铺视图
- (void)addShopsView:(NSArray*)arr
{

    [scr removeFromSuperview];
    
    //shareicons = @[[UIImage imageFromString:@"qq"],[UIImage imageFromString:@"weixin"],[UIImage imageFromString:@"tencent"],[UIImage imageFromString:@"sina"]];
    
    _row = (int)(arr.count/2);
    
    if (arr.count%2) {
        
        _row++;
        
    }
    if (arr.count==1) {
        
        _row =1;
    }
    
    scr = [[BeeUIScrollView alloc] init];

    [self.view insertSubview:scr aboveSubview:bgimg];
    [scr mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).offset(165);
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(-70);
        
    }];

    for (int i = 0; i<_row; i++) {
        
        UIView *cellBg = [[UIView alloc] initWithFrame:CGRectMake(0, i*120, self.bounds.size.width, 110)];
        cellBg.backgroundColor = [UIColor clearColor];
        [scr addSubview:cellBg];
        [scr setContentSize:CGSizeMake(self.bounds.size.width, CGRectGetMaxY(cellBg.frame))];
        
        
        UIImageView *storeNameImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"storeNmae"]];
        storeNameImg.frame = CGRectMake(10, 0, 21, 100);
        [cellBg addSubview:storeNameImg];
        storeNameImg.contentMode = UIViewContentModeScaleAspectFit;

        
        UIImageView *storeNameImgrig = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"storeNmae"]];
        storeNameImgrig.frame = CGRectMake(self.bounds.size.width-30, 0, 21, 100);
        [cellBg addSubview:storeNameImgrig];
        storeNameImgrig.contentMode = UIViewContentModeScaleAspectFit;

        
        UIImageView *bottomBook = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_cell_bg"]];
        bottomBook.frame = CGRectMake((cellBg.size.width-240)/2, cellBg.bounds.size.height-29, 240, 57/2);
        [cellBg addSubview:bottomBook];
        bottomBook.contentMode = UIViewContentModeScaleAspectFit;

        
        _col = (i>arr.count/2-1)?1:2;
        
        if (arr.count==1) {
            
            _col = 1;
        }
        
        for (int j = 0; j<_col; j++) {
            
            
            
            BeeUIButton *btn = [[BeeUIButton alloc] init];
            btn.tagString = [NSString stringWithFormat:@"%d|%d",i,j];
            
            //取model
            Shop *ss = arr[2*i+j];
            int index = [arr indexOfObject:ss];
            if (index%2==0 && index < arr.count) {
                //left
                
                UILabel *sname = [[UILabel alloc] initWithFrame:CGRectMake(14, 20, 14, 12*6)];
                sname.numberOfLines = 0;
                sname.font = [UIFont systemFontOfSize:12];
                [cellBg addSubview:sname];
                sname.text = ss.title;
                [cellBg bringSubviewToFront:sname];
                
                
            }else{
            
                UILabel *sname = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width-30+3, 20, 14, 12*6)];
                sname.numberOfLines = 0;
                sname.font = [UIFont systemFontOfSize:12];
                [cellBg addSubview:sname];
                sname.text = ss.title;
                [cellBg bringSubviewToFront:sname];
            
            }
            
            [btn addTarget:self action:@selector(shopBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            btn.frame = CGRectMake(5+(cellBg.size.width-240)/2+j*130, 10, 100, 80);
            
            BeeUIImageView *imgv = [[BeeUIImageView alloc] initWithFrame:CGRectMake(0, 0, btn.size.width, btn.size.height)];
            [btn addSubview:imgv];
            [btn sendSubviewToBack:imgv];
            
            [imgv GET:[NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].imageUrl,ss.pic] useCache:YES placeHolder:[UIImage imageFromString:@"triger.jpg"]];
            imgv.contentMode = UIViewContentModeScaleAspectFit;
            
            [cellBg addSubview:btn];
            UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake((btn.size.width-70)/2, btn.size.height-5, 70, 14)];
            lab.text = ss.storeGradeName;
            lab.textColor = [UIColor whiteColor];
            lab.backgroundColor = RGB(153, 0, 16);
            lab.layer.cornerRadius = 5;
            lab.layer.masksToBounds = YES;
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:14];
            [btn addSubview:lab];
        }
    }


}
#pragma mark - 支付视图
- (void)createPayView
{

    NSArray *payTypes = @[@{@"icon":[UIImage imageFromString:@"zfb"],@"title":@"支付宝支付"}                          ];
    
    self.payList = [[BeeUIScrollView alloc] initWithFrame:CGRectMake(0, 160, self.size.width, self.size.height-160-44)];
    [self.view addSubview:self.payList];
    [self createBottomPayView];
    __weak HomeBoard *weaksef = self;
    self.payList.lineCount = 1;
    self.payList.animationDuration = 0.25f;
    
    self.payList.whenReloading = ^{
    
        weaksef.payList.total = self.goodsArr.count+1+1+payTypes.count+1;
        int offset = 0;
        
        for (int i = 0; i<self.goodsArr.count; i++) {
            
            
            BeeUIScrollItem *goodsItem = weaksef.payList.items[offset];
            goodsItem.size = CGSizeMake(weaksef.payList.size.width, 64);
            goodsItem.clazz = [PayGoodsCell class];
            goodsItem.data = weaksef.goodsArr[i];
            offset++;
        }
        
        int nums = 0;
        float price = 0.00;
        
        for (CartM *cm in weaksef.goodsArr) {
            
            nums+=[cm.goodsNum intValue];
            price+=[cm.goodsNum intValue]*[cm.goods.price floatValue];
            
        }
        NSDictionary *numDic = @{@"nums":[NSString stringWithFormat:@"%d",nums],@"price":[NSString stringWithFormat:@"%.2f",price]};
        
        BeeUIScrollItem *allItem = weaksef.payList.items[offset];
        allItem.size = CGSizeMake(weaksef.payList.size.width, 64);
        allItem.clazz = [PayAllNumCell class];
        allItem.data = numDic;
        offset++;
        
        BeeUIScrollItem *addItem = weaksef.payList.items[offset];
        addItem.size = CGSizeMake(weaksef.payList.size.width, 110);
        addItem.data = weaksef.add;
        addItem.clazz = [PayAddressCell class];
        offset++;
        
        for (int j = 0; j<payTypes.count; j++) {
            
            BeeUIScrollItem *payItem = weaksef.payList.items[offset];
            payItem.size = CGSizeMake(weaksef.payList.size.width, 44);
            payItem.clazz = [PayTypeCell class];
            payItem.data = [payTypes safeObjectAtIndex:j];
            offset++;
        }
        
       
        
        BeeUIScrollItem *feeItem = weaksef.payList.items[offset];
        feeItem.size = CGSizeMake(weaksef.payList.size.width, 44);
        feeItem.clazz = [FeeItemCell class];
        feeItem.data = [NSString stringWithFormat:@"配送费用:    %@",weaksef.fee.length==0?@"0":weaksef.fee];
        offset++;
    
    };
}
- (void)createBottomPayView
{
    
    payBottomV = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height-44, self.bounds.size.width, 44)];
    payBottomV.clipsToBounds = NO;
    [self.view addSubview:payBottomV];
    
    UIImageView *leftbg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width/2, 44)];
    leftbg.image = [UIImage imageNamed:@"cartbg"];
    [payBottomV addSubview:leftbg];
    [payBottomV sendSubviewToBack:leftbg];
    
    UIImageView *cartIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cartIcon"]];
    cartIcon.frame = CGRectMake(10, -20, 60, 60);
    cartIcon.clipsToBounds = NO;
    [payBottomV addSubview:cartIcon];
    
    NSArray *cars = self.goodsArr;
    int nums=0;
    float price=0.00;
    for (CartM *cm in cars) {
        nums+=[cm.goodsNum integerValue];
        price+= [cm.goodsNum integerValue]*[cm.goods.price floatValue];
    }
    
    UILabel *numLab = [[UILabel alloc] initWithFrame:CGRectMake(45, 2, 20, 20)];
    numLab.backgroundColor = RGB(245, 34, 71);
    numLab.text = [NSString stringWithFormat:@"%d",nums];
    numLab.textAlignment = NSTextAlignmentCenter;
    numLab.textColor = [UIColor whiteColor];
    numLab.font = [UIFont systemFontOfSize:14];
    numLab.layer.cornerRadius = 10;
    numLab.layer.masksToBounds = YES;
    [cartIcon addSubview:numLab];
    
    UILabel *priceLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cartIcon.frame)+5, 10, 100, 20)];
    priceLab.text = [NSString stringWithFormat:@"共%.2f元",price];
    priceLab.font = [UIFont systemFontOfSize:16];
    [payBottomV addSubview:priceLab];
    
    
    
    UIButton *payBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftbg.frame), 0, self.bounds.size.width/2, 44)];
    [payBtn setTitle:@"立即支付" forState:UIControlStateNormal];
    [payBtn addTarget:self action:@selector(paymoneyBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    payBtn.backgroundColor = RGB(245, 34, 71);
    [payBottomV addSubview:payBtn];
    
}

#pragma mark -首页
- (void)addUI
{

    bgimg = [[UIImageView alloc] initWithFrame:self.bounds];
    bgimg.image = [UIImage imageNamed:@"home-bg"];
    [self.view addSubview:bgimg];
    [self.view sendSubviewToBack:bgimg];
    
    TopView *headBg = [[TopView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 165)];
    [self.view addSubview:headBg];
    
    //支付style
    if ([self.homeType isEqualToString:@"pay"]) {
        
        [self createPayView];
        return;
    }
    
    if ([self.homeType isEqualToString:@"fanli"]) {
        
        [self createFanliView];
        return;
    }
    //
    [self addShopsView:shopDatas];
    //
}
#pragma mark 返利说明
- (void)createFanliView{

    FanLiCell *liCell = [[FanLiCell alloc] initWithFrame:CGRectMake(10, 165, self.width-20, 300)];
    liCell.RELAYOUT();
    [self presentModalView:liCell animated:NO];
    
    
}

Shop *mysp;
# pragma mark ======添加底部视图
- (void)addBottomView:(NSArray *)infos{

    Member *mem = [infos firstObject];
    Shop *myshop = infos[1];
    mysp = myshop;
    NSString *flag = infos[2];
    UIView *vv = (UIView*)[self.view viewWithTag:9901];
    [vv removeFromSuperview];
    
    UIView *bottomV = [[UIView alloc] initWithFrame: CGRectMake(0, self.bounds.size.height-70, self.bounds.size.width, 70)];
    bottomV.tag = 9901;
    bottomV.backgroundColor = [UIColor clearColor];
    [self.view addSubview:bottomV];
    
    UIImageView *bottombg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bottom-bg"]];
    bottombg.frame = CGRectMake(0, 0, self.bounds.size.width, 70);
    [bottomV addSubview:bottombg];
    [bottomV sendSubviewToBack:bottombg];
    
    UIButton *myStoreBtn = [[UIButton alloc] init];
    [myStoreBtn setBackgroundImage:[UIImage imageNamed:@"triger.jpg"] forState:UIControlStateNormal];
    [myStoreBtn addTarget:self action:@selector(myShopClick:) forControlEvents:UIControlEventTouchUpInside];
    myStoreBtn.frame = CGRectMake(5, 5, 60, 60);
    [bottomV addSubview:myStoreBtn];
    
    
    BeeUIImageView *img = [[BeeUIImageView alloc] initWithFrame:CGRectMake(0, 0, myStoreBtn.size.width, myStoreBtn.size.height)];
    img.tag = 7989;
    [myStoreBtn addSubview:img];
    [myStoreBtn bringSubviewToFront:img];
    NSString *imgPath = [NSString stringWithFormat:@"%@/%@",[HttpRequest sharedInstance].imageUrl,mem.pic];
    [img GET:imgPath useCache:YES placeHolder:[UIImage imageNamed:@"triger.jpg"]];
    img.contentMode = UIViewContentModeScaleAspectFit;
    
    
    UIButton *safeBtn = [[UIButton alloc] init];
    if ([flag isEqualToString:@"true"] ) {
        
        [safeBtn setBackgroundImage:[UIImage imageNamed:@"safeStore"] forState:UIControlStateNormal];
    }else{
    
        [safeBtn setBackgroundImage:[UIImage imageNamed:@"spider"] forState:UIControlStateNormal];
        [safeBtn setEnabled:NO];

    }
    [safeBtn addTarget:self action:@selector(safeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    safeBtn.frame = CGRectMake(bottomV.size.width-65, 5, 60, 60);
    [bottomV addSubview:safeBtn];
    
    UILabel *topLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(myStoreBtn.frame)+10, 2, 200, 18)];
    topLab.backgroundColor = [UIColor clearColor];
    topLab.text = myshop.title;
    topLab.tag = 7900;
    topLab.font = [UIFont systemFontOfSize:14];
    topLab.textColor = RGB(61, 22, 7);
    [bottomV addSubview:topLab];
    
    UIImageView *gradeImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bottom-bg"]];
    gradeImg.frame = CGRectMake(CGRectGetMaxX(myStoreBtn.frame)+10, CGRectGetMaxY(topLab.frame), 30, 30);
    [bottomV addSubview:gradeImg];
    NSString *imgName = [NSString stringWithFormat:@"grade_0%d",[myshop.gradeId intValue]];
    gradeImg.image = [UIImage imageNamed:imgName];
    
    UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(gradeImg.frame)+5, CGRectGetMaxY(gradeImg.frame)-15, 125, 60)];
    
    progressView.progress = [[myshop.gradePercent substringToIndex:2] floatValue]/100;
    progressView.tintColor = RGB(71.0, 38.0, 20.0);
    [bottomV addSubview:progressView];
    
    UILabel *botomLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(myStoreBtn.frame)+10, bottomV.size.height-20, 200, 18)];
    botomLab.tag = 7901;
    botomLab.backgroundColor = [UIColor clearColor];
    botomLab.text = myshop.slogan;
    botomLab.font = [UIFont systemFontOfSize:12];
    botomLab.textColor = RGB(61, 22, 7);
    [bottomV addSubview:botomLab];
  

}

#pragma mark - 进入店铺
- (void)shopBtnClick:(BeeUIButton *)btn
{

    if ([SendIFAPPDefault shareAppDefault].userToken.length == 0) {
        
        [self presentLoginView];
        return;
    }
    
    
    NSString *tag = btn.tagString;
    int row = [[[tag componentsSeparatedByString:@"|"] firstObject] intValue];
    int col = [[[tag componentsSeparatedByString:@"|"] lastObject] intValue];
    int index = 2*row+col;
    
    ShopBoard *shb = [ShopBoard board];
    shb.sp = shopDatas[index];
    [self.stack pushBoard:shb animated:YES];

}
#pragma mark - 登陆视图
- (void)presentLoginView
{

    LoginCell *logcell = [[LoginCell alloc] initWithFrame:CGRectMake(10, 70, self.size.width-20, 410)];
    [self.view bringSubviewToFront:logcell];
    logcell.RELAYOUT();
    [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
}
#pragma mark - 保险箱视图
- (void)safeBtnClick:(UIButton*)safeB
{

    //
    [self dismissModalViewAnimated:YES];
    
    
    if ([[SendIFAPPDefault shareAppDefault].loginState intValue] == 0) {
        
        
        [self presentLoginView];
        
        return;
    }
    
    //
    
   
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isset"] intValue] !=0) { //已经注册保险箱账号
    
        SafeBoxLoginCell *logcell = [[SafeBoxLoginCell alloc] initWithFrame:CGRectMake(10, 160, self.size.width-20, 220)];
        [self.view bringSubviewToFront:logcell];
        logcell.data = @"pass";
        logcell.RELAYOUT();
        [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
        
    }else{
    
        
        [self presentLoginSafeBox];
    }



    
    
    
}
- (void)presentLoginSafeBox
{
    
    SafeBoxLoginCell *logcell = [[SafeBoxLoginCell alloc] initWithFrame:CGRectMake(10, 160, self.size.width-20, 220)];
    [self.view bringSubviewToFront:logcell];
    logcell.data = @"protect";
    logcell.RELAYOUT();
    [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
    
}
#pragma mark - 跳转到我的店铺
- (void)myShopClick:(UIButton *)btn
{

    if ([[SendIFAPPDefault shareAppDefault].loginState intValue]) {
        
        //已经登录
        //[self presentEditInfoView];
        if (mysp.id.length==0) {
            
            [self presentMessageTips:@"没有店铺"];
            return;
        }
        ShopBoard *sboard = [ShopBoard board];
        sboard.sp = mysp;
        [self.stack pushBoard:sboard animated:YES];
        
        
    }else
    {
    
        LoginCell *logcell = [[LoginCell alloc] initWithFrame:CGRectMake(10, 70, self.size.width-20, 410)];
        [self.view bringSubviewToFront:logcell];
        logcell.RELAYOUT();
        [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
        
    }

}

#pragma mark - 顶部视图事件
ON_SIGNAL3(TopView, HEADBTNCLICK, signal)
{
    
    BeeUIButton *btn = (BeeUIButton*)signal.object;
    
    if (btn.tag == 100) {
        
        UIViewController *fvc;
        RevealViewController *rVC;
        HomeBoard *fronVC = [[HomeBoard alloc] init];

        fvc = fronVC;
        
        rVC = [[RevealViewController alloc] init];
        
        BeeUIStack *navigationControllerF = [[BeeUIStack alloc] initWithRootViewController:fvc];
        BeeUIStack *navigationControllerR = [[BeeUIStack alloc] initWithRootViewController:rVC];
        RevealController *revealController = [[RevealController alloc] initWithFrontViewController:navigationControllerF rearViewController:navigationControllerR];
        AppDelegate *app = (AppDelegate*)[AppDelegate sharedInstance];
        app.viewController = revealController;
        [app.window setRootViewController:app.viewController];

        
    }else if (btn.tag == 101)
    {
    
        SortBoard *sb = [SortBoard board];
        [self.stack pushBoard:sb animated:YES];
        
    
    }else if (btn.tag == 102){

        [self dismissModalViewAnimated:NO];
        [self presentFriendView];
        

    }else if (btn.tag == 103)
    {

        [self dismissModalViewAnimated:NO];
        [self presentNewsView];
    
    }
}
- (void)presentNewsView
{

    //公告
    
    NewsCell *newsCell = [[NewsCell alloc] initWithFrame:CGRectMake(10, 120, self.size.width-20, self.size.height-120-70)];
    newsCell.RELAYOUT();
    [self presentModalView:newsCell animated:YES transitionType:BeeUITransitionTypeDefault];

}
#pragma mark - 好友视图
- (void)presentFriendView
{

    fcell = [[FriendCell alloc] initWithFrame:CGRectMake(10, 120, self.size.width-20, self.size.height-120-70)];
    fcell.clipsToBounds = NO;
    fcell.RELAYOUT();

    
    
    [self presentModalView:fcell animated:YES transitionType:BeeUITransitionTypeDefault];

}

ON_SIGNAL3(BeeUIBoard, MODALVIEW_WILL_HIDE, signal)
{

    [UIView animateWithDuration:0.3 animations:^{
        
        addv.frame = CGRectMake(0, fcell.size.height+70, fcell.size.width, 70);
        
    } completion:^(BOOL finished) {
        
        
    }];

}
#pragma mark - 登陆
ON_SIGNAL3(LoginCell, loginbtn, signal)
{

    LoginCell *cell = (LoginCell*)signal.sourceCell;
    NSString *phone = $(cell).FIND(@"#phonetf").text;
    NSString *pass = $(cell).FIND(@"#passtf").text;
    if (phone.length == 0 || pass.length==0) {
        
        [self presentMessageTips:@"请输入账号或密码"];
        return;
    }
    
    NSDictionary *dic = @{@"mobile":phone,@"passwd":pass};
    self.MSG(HttpAPI.LOGIN).INPUT(@"body",dic);
    
}
ON_MESSAGE3(HttpAPI, LOGIN, msg)
{

    if (msg.sending)
    {
        [self presentLoadingTips:@"登陆中..."];
    }else{
    
        [self dismissTips];
        
        if (msg.succeed)
        {
           

            Status *sta = msg.GET_OUTPUT(@"status");
            
            if ([sta.code intValue] !=10000) {
                
                [self presentMessageTips:sta.message];
                return;
            }
            [self dismissModalViewAnimated:YES];
            NSString *tok = [SendIFAPPDefault shareAppDefault].userToken.length==0?@"":[SendIFAPPDefault shareAppDefault].userToken;
            NSDictionary *dic = @{@"source":@"",@"token":tok,@"pageNumber":@"1",@"pageSize":@"1000"};
            self.MSG(HttpAPI.GETHOME).INPUT(@"body",dic);
            
            [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:[NSDate timeStamp]] forKey:@"login_time"];
            [[NSUserDefaults standardUserDefaults] synchronize];
     
 
            
        }else if (msg.failed)
        {
        

        }
    
    }

}
#pragma mark - 跳转注册
ON_SIGNAL3(LoginCell, registerbtn, signal)
{
    
    
    //[self dismissModalViewAnimated:fcell transitionType:BeeUITransitionTypeDefault];
    [self dismissModalViewAnimated:YES];
    RegisterCell *regicell = [[RegisterCell alloc] initWithFrame:CGRectMake(10, 70, self.size.width-20, 410)];
    [self.view bringSubviewToFront:regicell];
    regicell.RELAYOUT();
    [self presentModalView:regicell animated:YES transitionType:BeeUITransitionTypeDefault];
    
}
#pragma mark - 获取验证码
ON_SIGNAL3(RegisterCell, vercodebtn, signal)
{

    RegisterCell *cell = (RegisterCell*)signal.sourceCell;
    NSString *phone = $(cell).FIND(@"#phonetf").text;
    if (![phone isMobilephone]) {
        [self presentMessageTips:@"请输入有效的手机号"];
        return;
    }
    
    self.MSG(HttpAPI.GET_VERCODE).INPUT(@"body",@{@"mobile":phone,@"sign":@"pishajie"});

}
ON_MESSAGE3(HttpAPI, GET_VERCODE, msg)
{

    if (msg.sending)
    {
        [self presentLoadingTips:@"获取中..."];
    }else{
        
        [self dismissTips];
        
        if (msg.succeed)
        {
            Status *sa = msg.GET_OUTPUT(@"status");
            if ([sa.code isEqualToString:@"20000"]) {
                
                [self presentFailureTips:sa.message];
                
            }else{
            
                
            
            }
            
            
        }else if (msg.failed)
        {
            
        }
        
    }
}
#pragma mark - 注册事件
ON_SIGNAL3(RegisterCell, sureBtn, signal)
{

    RegisterCell *cell = (RegisterCell*)signal.sourceCell;
    NSString *phone = $(cell).FIND(@"#phonetf").text;
    NSString *vercode = $(cell).FIND(@"#vercodetf").text;
    NSString *pass = $(cell).FIND(@"#passtf").text;
    NSString *surepass = $(cell).FIND(@"#surepasstf").text;
    
    if (![surepass isEqualToString:pass]) {
        [self presentMessageTips:@"两次输入的密码不一致！"];
        return;
    }
    if (phone.length==0||vercode.length==0||pass.length==0||surepass.length==0) {
        
        [self presentMessageTips:@"请完善注册信息"];
        return;
    }
    
    
    NSDictionary *dic = @{@"mobile":phone,@"passwd":pass,@"code":vercode,@"from":@""};
    self.MSG(HttpAPI.REGISTER).INPUT(@"body",dic);

}
ON_MESSAGE3(HttpAPI, REGISTER, msg)
{
    
    if (msg.sending)
    {
        [self presentLoadingTips:@""];
    }else{
        
        [self dismissTips];
        
        if (msg.succeed)
        {
            Status *sa = msg.GET_OUTPUT(@"status");
            if ([sa.code isEqualToString:@"20000"]) {
                
                [self presentFailureTips:sa.message];
                
            }else{
            
                [self dismissModalViewAnimated:YES];
                
            
            }
            
            [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:[NSDate timeStamp]] forKey:@"login_time"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            
            
            
        }else if (msg.failed)
        {
            
            [self presentMessageTips:@"网络错误"];
        }
        
    }
    
}

#pragma mark - 首页数据
ON_MESSAGE3(HttpAPI, GETHOME, msg)
{

    if (msg.sending)
    {
        [self presentLoadingTips:@"数据加载中"];
        
    }else
    {
        [self dismissTips];
        
        if (msg.succeed)
        {
        
            NSArray *shops = msg.GET_OUTPUT(@"shops");
            if (shops.count==0) {
                [self presentMessageTips:@"暂无店铺"];
                
            }
            
            shopDatas = [NSMutableArray arrayWithArray:shops];
            //save
            [Shop saveObject:shops forKey:@"home.shops"];
            [self addShopsView:shops];
            [self addBottomView:@[msg.GET_OUTPUT(@"member")?:[Member new],msg.GET_OUTPUT(@"myshop")?:[Shop new],msg.GET_OUTPUT(@"flag")?:@""]];
            Member *me = msg.GET_OUTPUT(@"member");
            [[NSUserDefaults standardUserDefaults] setObject:me.isset forKey:@"isset"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            
        }else if (msg.failed)
        {
            NSString *s  = msg.GET_OUTPUT(@"message");
            s = s.length==0?@"网络故障":s;
            [self presentFailureTips:s];
            
        }
        
    }
}
#pragma mark - 忘记密码事件
ON_SIGNAL3(LoginCell, forgetbtn, signal)
{


    [self dismissModalViewAnimated:YES];
    FindPassCell *findcell = [[FindPassCell alloc] initWithFrame:CGRectMake(10, 70, self.size.width-20, 410)];
    [self.view bringSubviewToFront:findcell];
    findcell.RELAYOUT();
    [self presentModalView:findcell animated:YES transitionType:BeeUITransitionTypeDefault];

}
ON_SIGNAL3(FindPassCell, vercodebtn, signal)
{

    FindPassCell *cell = (FindPassCell*)signal.sourceCell;
    NSString *phone = $(cell).FIND(@"phonetf").text;
    _mphone = phone;
    if (![phone isMobilephone]) {
        
        [self presentMessageTips:@"请输入有效的手机号"];
        return;
    }
    NSDictionary *dic = @{};
    self.MSG(HttpAPI.randomcode).INPUT(@"body",dic);

}
ON_SIGNAL3(FindPassCell, sureBtn, signal)
{

    
    //sure
    FindPassCell *cell = (FindPassCell*)signal.sourceCell;
    
    NSString *vercode = $(cell).FIND(@"#vercodetf").text;
    NSString *pass = $(cell).FIND(@"#passtf").text;
    
    
    if (vercode.length==0||pass.length==0) {
        
        [self presentMessageTips:@"请完善信息"];
        return;
    }
    
    NSDictionary *dic = @{@"mobile":_mphone,@"verificationCode":vercode,@"password":pass};
    self.MSG(HttpAPI.resetpassword).INPUT(@"body",dic);

}
#pragma mark - 找回密码逻辑处理
ON_MESSAGE3(HttpAPI, randomcode, msg)
{

    
    if (msg.sending) {
        
        
        [self presentLoadingTips:@""];
        
        
    }else{
    
        [self dismissTips];
        if (msg.succeed) {
            
            NSString *randcode = msg.GET_OUTPUT(@"randcode");
            NSString *token = msg.GET_OUTPUT(@"token");
            
            NSDictionary *dic = @{@"token":token,@"mobile":_mphone,@"code":randcode};
            self.MSG(HttpAPI.validate).INPUT(@"body",dic);
            
            
        }else if (msg.failed){
            
            Status *sta = msg.GET_OUTPUT(@"status");
            [self presentFailureTips:sta.message];
            
        }
    
    }
    


}

ON_MESSAGE3(HttpAPI, validate, msg)
{

    if (msg.sending) {
        
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
        }else if (msg.failed){

        }
    }
}
ON_MESSAGE3(HttpAPI, resetpassword, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                
            }else{
            
                [self dismissModalViewAnimated:YES];
            }
            
        }else if (msg.failed){
            
            
            
        }
        
    }

}

#pragma mark - 编辑个人信息

- (void)presentEditInfoView
{
    
    EditInfoCell *cell = [[EditInfoCell alloc] initWithFrame:CGRectMake(10, 80, self.size.width-20, self.view.bounds.size.height-80-75)];
    cell.RELAYOUT();
    [self presentModalView:cell animated:YES];
    if (self.imagePath) {
        
        $(cell).FIND(@"userIcon").DATA([UIImage imageWithContentsOfFile:self.imagePath]);

    }
    
}

ON_SIGNAL3(EditInfoCell, logout, signal)
{


    
    self.MSG(HttpAPI.LOGOUT).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken});

   
    
}
ON_MESSAGE3(HttpAPI, LOGOUT, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@"正在退出账号"];
        
    }else{
        
        [self dismissTips];
        [self dismissModalViewAnimated:YES];
        [[SendIFAPPDefault shareAppDefault] setLoginState:@"0"];
        [[SendIFAPPDefault shareAppDefault] setUserToken:nil];
        [[SendIFAPPDefault shareAppDefault] setLoginName:nil];
        [[SendIFAPPDefault shareAppDefault] setIsBoxAccount:@"0"];
        [self presentLoginView];
        
        if (msg.succeed) {
            
            
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }


}


ON_SIGNAL3(EditInfoCell, suremod, signal)
{

     EditInfoCell *cell = (EditInfoCell *)signal.sourceCell;
     NSString *shopName = $(cell).FIND(@"shopnametf").text;
     NSString *ownername = $(cell).FIND(@"ownernametf").text;
     NSString *phone = $(cell).FIND(@"phonetf").text;
     NSString *ad = $(cell).FIND(@"adtf").text;
     NSData *data = [[NSData alloc] initWithContentsOfFile:self.imagePath];
    //开始修改信息
    if ([shopName empty] || [ad empty] || [phone empty] || [ownername empty]) {
        
        [self presentMessageTips:@"编辑信息不完整"];
        return;
    }
    
    
//    NSDictionary *dic = @{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"shopName":shopName,@"memberName":ownername,@"mobile":phone,@"slogan":ad,@"pic":data};
    
    //self.MSG(HttpAPI.member_update).INPUT(@"body",dic);
    
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://103.10.87.167:8096/service/member_update.php"]];
    request.requestMethod = @"POST";
    request.delegate = self;
    [request setDidFinishSelector:@selector(requestSuccess:)];
    [request setDidFailSelector:@selector(requestFailed:)];
    request.postFormat = ASIMultipartFormDataPostFormat;
    [request addPostValue:[SendIFAPPDefault shareAppDefault].userToken forKey:@"token"];
    [request addPostValue:shopName forKey:@"shopName"];
    [request addPostValue:ownername forKey:@"memberName"];
    [request addPostValue:phone forKey:@"mobile"];
    [request addPostValue:ad forKey:@"slogan"];
    
    if (data) {
        
    [request addFile:data withFileName:@"photo.png" andContentType:@"image/png" forKey:@"pic"];
        
    }

    
    [self presentLoadingTips:@"正在修改"];
    [request startAsynchronous];
    
    



    
}

- (void)requestSuccess:(ASIHTTPRequest*)request
{

    [self dismissTips];
 
    NSDictionary *dic = [request.responseString objectFromJSONString];
    if ([dic[@"code"] intValue] != 10000) {
        
        [self presentFailureTips:dic[@"message"]];
    }else{
    
        [self presentMessageTips:@"修改成功"];
    }

}

- (void)requestFailed:(ASIHTTPRequest*)request
{
    [self dismissTips];
    [self presentFailureTips:@"网络错误"];
}


ON_MESSAGE3(HttpAPI, member_update, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@"修改信息"];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            [self presentMessageTips:@"修改成功"];
            
            
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }

    

}

ON_SIGNAL3(EditInfoCell, decoratebtn, signal)
{
    
    DecorateBoard *deboard = [DecorateBoard board];
    [self.stack pushBoard:deboard animated:YES];
}

ON_SIGNAL3(EditInfoCell, qercodebtn, signal)
{

    
    //[self presentMessageTips:@"需上线后提供"];

}
#pragma mark - 拍照
ON_SIGNAL3(EditInfoCell, changephotobtn, signal)
{

    EditInfoCell *cell = (EditInfoCell *)signal.sourceCell;

    editCell = cell;
    BeeUIActionSheet *sheet = [[BeeUIActionSheet alloc] init];
    [sheet addButtonTitle:@"拍照" signal:@"takephoto"];
    [sheet addButtonTitle:@"相册" signal:@"album"];
    [sheet addDestructiveTitle:@"取消" signal:@"cancel"];
    [sheet showInView:self.view];
    
    //获取Documents文件夹目录
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [path objectAtIndex:0];
    //指定新建文件夹路径
    NSString *imageDocPath = [documentPath stringByAppendingPathComponent:@"ImageFile"];
    //创建ImageFile文件夹
    [[NSFileManager defaultManager] createDirectoryAtPath:imageDocPath withIntermediateDirectories:YES attributes:nil error:nil];
    //保存图片的路径
    self.imagePath = [imageDocPath stringByAppendingPathComponent:@"image.png"];
    
}

ON_SIGNAL2(takephoto, signal)
{

    
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
       
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = sourceType;
        [self presentModalViewController:picker animated:YES];
        
    }else{
    
        [self presentMessageTips:@"该设备无摄像头"];
    
    }
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{


    //当图片不为空时显示图片并保存图片
    if (image != nil) {
        //图片显示在界面上
        //[changeImg setBackgroundImage:image forState:UIControlStateNormal];
        
        //以下是保存文件到沙盒路径下
        //把图片转成NSData类型的数据来保存文件
        image = [image resize:CGSizeMake(100, 100)];
        NSData *data;
        //判断图片是不是png格式的文件
        if (UIImagePNGRepresentation(image)) {
            //返回为png图像。
            data = UIImagePNGRepresentation(image);
        }else {
            //返回为JPEG图像。
            data = UIImageJPEGRepresentation(image, 1.0);
        }
        
        $(editCell).FIND(@"userIcon").DATA(image);
 
        //保存
        [[NSFileManager defaultManager] createFileAtPath:self.imagePath contents:data attributes:nil];
        
    }
    //关闭相册界面
    [picker dismissModalViewControllerAnimated:YES];

}
ON_SIGNAL2(album, signal)
{

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //资源类型为图片库
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    //设置选择后的图片可被编辑
    picker.allowsEditing = YES;
    [self presentModalViewController:picker animated:YES];
    
}
ON_SIGNAL3(EditInfoCell, addressone, signal)
{

    EditInfoCell *cell = (EditInfoCell*)signal.sourceCell;
    Member *mer = cell.data;
    Address *adr = [ mer.address firstObject];
    [self presentAddressView:adr];
}

- (void)presentAddressView:(Address*)adr
{

    [self dismissModalViewAnimated:YES];
    
    EditInfoAddressCell *cell = [[EditInfoAddressCell alloc] initWithFrame:CGRectMake(10, 120, self.size.width-20, self.view.bounds.size.height-120-75)];
    cell.data = adr;
    cell.RELAYOUT();
    
    [self presentModalView:cell animated:YES transitionType:BeeUITransitionTypeCube];
}
ON_SIGNAL3(EditInfoAddressCell, suremod, signal)
{
    
    //修改地址;
    Address *adr = signal.sourceCell.data;
    EditInfoAddressCell *cell = (EditInfoAddressCell*)signal.sourceCell;
    
    
    NSString *name = $(cell).FIND(@"nametf").text;
    NSString *phone = $(cell).FIND(@"phonetf").text;
    NSString *addr = $(cell).FIND(@"addrtf").text;
    
    if (name.length) {
        
        adr.name = name;
    }
    
    if (phone.length) {
        
        adr.mobile = phone;
    }
    
    if (addr.length) {
        
        adr.address = addr;
    }
    
    if (adr) {
        
        self.MSG(HttpAPI.address_update).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"id":adr.id,@"name":adr.name,@"mobile":adr.mobile,@"address":adr.address,@"Is_default":@"1"});
    }else{
    
       
        self.MSG(HttpAPI.address_add).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"name":name,@"mobile":phone,@"address":addr,@"Is_default":@"1"});
    }

    
    

}
ON_MESSAGE3(HttpAPI, address_update, msg)
{



    if (msg.sending) {
        
        [self presentLoadingTips:@"正在修改"];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            [self presentMessageTips:@"修改成功"];
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }



}
ON_MESSAGE3(HttpAPI, address_add, msg)
{



    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            [self presentMessageTips:@"添加成功"];
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }



}

ON_SIGNAL3(EditInfoAddressCell, back, signal)
{
    
    [self dismissModalViewAnimated:YES];
    [self presentEditInfoView];
}

#pragma mark - 保险箱登录视图signal

ON_SIGNAL3(SafeBoxLoginCell, sureopen, signal)
{

    BeeUIButton *btn = (BeeUIButton*)signal.sourceView;
    SafeBoxLoginCell *logcell = (SafeBoxLoginCell*)signal.sourceCell;
    
    if ([btn.title isEqualToString:@"确认打开"]) {
        
        //首次打开，需注册
        
        NSString *ques = $(logcell).FIND(@"questionTf").text;
        NSString *ans = $(logcell).FIND(@"answerTf").text;
        NSString *pass = $(logcell).FIND(@"passTf").text;
        
        if (ques.length == 0||ans.length == 0||pass.length == 0) {
            
            [self presentMessageTips:@"请完善信息!"];
            return;
        }
        
        self.MSG(HttpAPI.box_reg).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"question":ques,@"answer":ans,@"boxPassword":pass});
        
    }else if([btn.title isEqualToString:@"确认"]){
    
        //找回密码
        
    }else{
        
       //确认密码，打开，展示内容
        
        NSString *pass = $(logcell).FIND(@"answerTf").text;
        if (pass.length == 0) {
            [self presentMessageTips:@"请输入登录密码"];
            return;
        }
        
        self.MSG(HttpAPI.box_login).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"password":pass});
       
        
    }
    
    
}

ON_SIGNAL3(SafeBoxLoginCell, boxlogin, signal)
{

    //显示登录界面
    [self dismissModalViewAnimated:YES];
    SafeBoxLoginCell *logcell = [[SafeBoxLoginCell alloc] initWithFrame:CGRectMake(10, 160, self.size.width-20, 220)];
    [self.view bringSubviewToFront:logcell];
    logcell.data = @"pass";
    logcell.RELAYOUT();
    [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];

}
ON_MESSAGE3(HttpAPI, box_login, msg)
{
    
    
    if (msg.sending) {
        
        [self presentLoadingTips:@"正在登录"];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {


            
            //登录成功显示内容界面
            [self dismissModalViewAnimated:YES];
            
            [[SendIFAPPDefault shareAppDefault] setIsBoxAccount:@"1"];
            NSDictionary *mystore = msg.GET_OUTPUT(@"mystore");
            NSArray *stores = msg.GET_OUTPUT(@"stores");
            NSDictionary *footerData = msg.GET_OUTPUT(@"footerData");
            [self presentContentSafeBoxView:@{@"mystore":mystore,@"stores":stores,@"footerdata":footerData}];
            
        }else{
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                
            }else
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }


   

}
ON_MESSAGE3(HttpAPI, box_reg, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@"正在注册账号"];
        
    }else{
    
        [self dismissTips];
        
        if (msg.succeed) {
            
            //注册成功显示登录界面
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            [self dismissModalViewAnimated:YES];
            [[SendIFAPPDefault shareAppDefault] setIsBoxAccount:@"1"];
            SafeBoxLoginCell *logcell = [[SafeBoxLoginCell alloc] initWithFrame:CGRectMake(10, 160, self.size.width-20, 220)];
            [self.view bringSubviewToFront:logcell];
            logcell.data = @"pass";
            logcell.RELAYOUT();
            [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
            
        }else{
        
            [self presentFailureTips:@"网络错误"];
        
        }
    
    }

}
ON_SIGNAL3(SafeBoxLoginCell, forgetsafepass, signal)
{

    [self dismissModalViewAnimated:YES];
//    SafeBoxLoginCell *logcell = [[SafeBoxLoginCell alloc] initWithFrame:CGRectMake(10, 160, self.size.width-20, 220)];
//    [self.view bringSubviewToFront:logcell];
//    logcell.data = @"forget";
//    logcell.RELAYOUT();
//    [self presentModalView:logcell animated:YES transitionType:BeeUITransitionTypeDefault];
    
    self.MSG(HttpAPI.aboutus).INPUT(@"body",@{});
    
    


}
ON_MESSAGE3(HttpAPI, aboutus, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
              
            }
            NSDictionary *infoD = msg.GET_OUTPUT(@"info");
            NSString *info = [NSString stringWithFormat:@"联系客服\n客服电话:%@\n邮箱:%@\nQQ:%@\n微信:%@\n公司尽快为你处理\n请耐心等待",infoD[@"phone"],infoD[@"mail"],infoD[@"qq"],infoD[@"weixin"]];
            
           ALERT_WARN(info);
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
    


}
#pragma mark - 保险柜内容视图
- (void)presentContentSafeBoxView:(NSDictionary*)data
{
    SafeBoxContentCell *cell = [[SafeBoxContentCell alloc] initWithFrame:CGRectMake(10, 60, self.size.width-20, 365)];
    [self.view bringSubviewToFront:cell];
    cell.data = data;
    cell.RELAYOUT();
    [self presentModalView:cell animated:YES transitionType:BeeUITransitionTypeDefault];
    
}
ON_SIGNAL3(SafeBoxContentCell, suretakemoney, signal)
{

    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if ([app.takeTf.text floatValue] < 500.0 || [app.shopMoneyLab.text floatValue]<=0.0 || [app.takeTf.text floatValue]>[app.shopMoneyLab.text floatValue]) {
        
        [self presentMessageTips:@"提款金额需大于500元或店铺资金不够"];
        return;
    }
    
    
    self.MSG(HttpAPI.cash).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"money":app.takeTf.text});
}

ON_SIGNAL3(SafeBoxContentCell, addmoney, signal)
{
    
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    if (app.moneyTf.text == 0) {
        
        [self presentMessageTips:@"请输入提款账户"];
        return;
    }
    self.MSG(HttpAPI.money_account).INPUT(@"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,@"cardNum":app.moneyTf.text});


}
ON_MESSAGE3(HttpAPI, cash, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
            }
            [self presentMessageTips:@"提款申请成功!"];
            
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
}
ON_MESSAGE3(HttpAPI, money_account, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
            

            [self presentMessageTips:@"修改成功"];
 
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
    


}

#pragma mark - 支付类型事件
ON_SIGNAL3(PayTypeCell, mask, signal)
{

    PayTypeCell *cell = (PayTypeCell*)signal.sourceCell;
    $(cell).FIND(@"check").DATA([UIImage imageFromString:@"checked_1"]);
    
    if (cell != _lastPayTypeCell) {
        
       $(_lastPayTypeCell).FIND(@"check").DATA([UIImage imageFromString:@"unchecked_1"]);
    }
    _lastPayTypeCell = cell;

}
- (void)paymoneyBtnClick
{

   
    if (_lastPayTypeCell == nil) {
        
        [self presentMessageTips:@"请选择一种支付方式"];
        return;
    }
    
    NSDictionary *dic = _lastPayTypeCell.data;
    
    if ([dic[@"title"] isEqualToString:@"支付宝支付"]) {
        
        self.MSG(HttpAPI.alipay).INPUT(
                                       @"body",@{@"token":[SendIFAPPDefault shareAppDefault].userToken,
                                                 @"orderId":self.orderId});
        
    }else if ([dic[@"title"] isEqualToString:@"银行卡支付"])
    {
        [self presentMessageTips:@"功能暂未开放!"];
        
    
    }else if ([dic[@"title"] isEqualToString:@"货到付款"])
    {
        [self presentMessageTips:@"请联系客服电话:400-5607812"];
        
    }



}
ON_MESSAGE3(HttpAPI, alipay, msg)
{

    if (msg.sending) {
        
        [self presentLoadingTips:@""];
        
    }else{
        
        [self dismissTips];
        
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentFailureTips:sta.message];
                return;
            }
            
           //开始支付
            NSString *rsa = msg.GET_OUTPUT(@"rsa");
            
            [[AlipaySDK defaultService] payOrder:rsa fromScheme:@"mypizza" callback:^(NSDictionary *resultDic) {
                
                BeeLog(@"resultDicxxxx%@",resultDic);
                
            }];
           
            
        }else{
            
            [self presentFailureTips:@"网络错误"];
            
        }
        
    }
    


}
#pragma mark - 分享
ON_SIGNAL3(FriendCell, SHAREBTN, signal)
{

    BeeUIButton *btn = (BeeUIButton*)signal.object;
    if (btn.tag == 1010) {
        
        [self presentMessageTips:@"暂未开放！"];
        
        
    }else if (btn.tag == 1011){
        [self presentMessageTips:@"暂未开放！"];
        
    
    }else if (btn.tag == 1012){
        
        [ShareWeiBo shareTencentWeiBoWithContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"inviurl"] image:[UIImage imageNamed:@"goodsPhoto"] delegate:self];
        
    }else if (btn.tag == 1013){
        
        [ShareWeiBo shareSinaWeiBoWithContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"inviurl"] image:[UIImage imageNamed:@"goodsPhoto"] delegate:self];
    }

}

#pragma mark - 搜索店铺
ON_SIGNAL3(BeeUITextField, RETURN, signal)
{
    
    BeeUITextField *tf = (BeeUITextField*)signal.sourceView;
    if (tf.tag == 9999) {
    self.MSG(HttpAPI.shop_search).INPUT(@"body",@{@"source":@"IOS",@"keywords":tf.text,@"pageNumber":@"1",@"pageSize":@"1000"});
    }

}
ON_MESSAGE3(HttpAPI, shop_search, msg)
{


    if (msg.sending) {
        
        [self presentLoadingTips:@"数据获取中"];
    }else{
        
        [self dismissTips];
        if (msg.succeed) {
            
            Status *sta = msg.GET_OUTPUT(@"status");
            if ([sta.code intValue] != 10000) {
                
                [self presentMessageTips:sta.message];
                return;
            }
            //
            NSArray *sps = msg.GET_OUTPUT(@"shops");
            shopDatas = [[NSMutableArray alloc] initWithArray:sps];
            if (sps.count == 0) {
                
                [self presentMessageTips:@"没有符合条件店铺"];
                return;
            }
            [self addShopsView:sps];
        }else{
            
            [self presentFailureTips:@"网络错误"];
        }
        
    }

}

#pragma mark - toCart
ON_SIGNAL3(TopView, GOTOCART, signal){

    CartBoard *board = [CartBoard board];
    [self.navigationController pushViewController:board animated:YES];

}
#pragma mark 我的连锁店铺
ON_SIGNAL3(FriendCell, chainbtn, signal){

    [self dismissModalViewAnimated:NO];
    MyLinksCell *liCell = [[MyLinksCell alloc] initWithFrame:CGRectMake(5, 145, self.width-10, 300)];
    liCell.RELAYOUT();
    [self presentModalView:liCell animated:NO];

}

ON_SIGNAL3(TopView, beginsearch, signal){

    NSString *keyw = signal.object;
    if (keyw.length==0) {
        
        [self presentMessageTips:@"请输入店铺名"];
        return;
    }
  self.MSG(HttpAPI.shop_search).INPUT(@"body",@{@"source":@"IOS",@"keywords":keyw,@"pageNumber":@"1",@"pageSize":@"1000"});

}
@end
